/**
 * 
 */
package com.google.nk.dictionary;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @author Duy Kien Ngo
 * 
 */
public class Home_Fragment extends Fragment implements TextWatcher{
	private TextView selection;
	private ListView listView;
	private ArrayAdapter<String> listAdapter;
	static final String[] FRUITS = new String[] { "Apple", "Avocado", "Banana",
			"Blueberry", "Coconut", "Durian", "Guava", "Kiwifruit",
			"Jackfruit", "Mango", "Olive", "Pear", "Sugar-apple" };
	 AutoCompleteTextView singleComplete;
	 
	 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		// TODO Auto-generated method stub
		View v = LayoutInflater.from(getActivity()).inflate(R.layout.home_frag,
				null);
		// text = (TextView) v.findViewById(R.id.textView);
		// text.setText("Home Screen"
	;
		singleComplete=(AutoCompleteTextView) v.findViewById(R.id.editauto);
		singleComplete.addTextChangedListener(this);
		// Thiết lập ArrayADapter
		singleComplete.setAdapter(new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, FRUITS));
		
		selection = (TextView) v.findViewById(R.id.selection);
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, FRUITS);
		listView = (ListView) v.findViewById(R.id.listV);
		listView.setAdapter(adapter);
		 // ListView Item Click Listener
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// ListView Clicked item index
				int itemPosition = position;
				// ListView Clicked item value
				String itemValue = (String) listView.getItemAtPosition(position);
				singleComplete.setText(itemValue);
				//Toast.makeText(getActivity(),  "Position :"+itemPosition+"  ListItem : " +itemValue, Toast.LENGTH_LONG).show();
			}

		});
		return v;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		selection.setText(singleComplete.getText());
	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		
	}
}
